package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/dish")
@Slf4j
@RequiredArgsConstructor
public class DishController {
    private final DishService dishService;

    /**
     * 创造
     *
     * @param dishDTO 碟形dto
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping
    public Result<?> create(@RequestBody DishDTO dishDTO) {
        dishService.create(dishDTO);
        return Result.success();
    }

    /**
     * 页
     *
     * @param dishPageQueryDTO 菜式页面查询dto
     * @return {@link Result}<{@link PageResult}>
     */
    @GetMapping("/page")
    public Result<PageResult> page(DishPageQueryDTO dishPageQueryDTO) {
        PageResult pageResult = dishService.page(dishPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 按ID删除批次
     *
     * @param ids ids
     * @return {@link Result}<{@link ?}>
     */
    @DeleteMapping
    public Result<?> deleteBatchByIds(@RequestParam List<Long> ids) {
        dishService.deleteBatchByIds(ids);
        return Result.success();
    }

    /**
     * 按id查询
     *
     * @param id id
     * @return {@link Result}<{@link ?}>
     */
    @GetMapping("/{id}")
    public Result<?> queryById(@PathVariable Long id) {
        DishVO dishVO = dishService.queryById(id);
        return Result.success(dishVO);
    }

    /**
     * 使现代化
     *
     * @param dishDTO 碟形dto
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping
    public Result<?> update(@RequestBody DishDTO dishDTO) {
        dishService.update(dishDTO);
        return Result.success();
    }

    /**
     * 更新状态
     *
     * @param id     id
     * @param status 地位
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping("/status/{status}")
    public Result<?> updateStatus(Long id, @PathVariable Integer status) {
        dishService.updateStatus(id, status);
        return Result.success();
    }

    @GetMapping("/list")
    public Result<List<DishVO>> dishList(String categoryId) {
        List<DishVO> diashList = dishService.dishList(categoryId);
        return Result.success(diashList);
    }

}
